import { request } from "../request"

const getCartData = async userId => {
  try {
    const res = await request({
      url: '/cart/all_data',
      method: 'post',
      data: {
        userId: userId
      }
    })
    return res
  } catch (error) {
    console.log(error);
  }
}

const upDateCartCount = async (userId, goodsId, newCount) => {
  try {
    const res = await request({
      url: '/cart/update_count',
      method: 'post',
      data: {
        userId,
        goodsId,
        newCount
      }
    })
    return res
  } catch (error) {
    console.log(error);
  }
}

const deleteGoods = async id => {
  try {
    const res = await request({
      url: '/cart/delete_goods',
      method: 'post',
      data: {
        id
      }
    })
    return res
  } catch (error) {
    console.log(error);
  }
}

const addGoods = async (goodsId, userId) => {
  try {
    const res = await request({
      url: '/cart/add_goods',
      method: 'post',
      data: {
        goodsId,
        userId
      }
    })
    return res
  } catch (error) {
    console.log(error);
  }
}

export {
  getCartData,
  upDateCartCount,
  deleteGoods,
  addGoods
}